@extends('admin.layout')
@section('title','专家管理页')
@section('content')

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" >
        <div class="col-md-12" id="content" >
            <!-- 配置文件 -->
            <script type="text/javascript" src="/assets/js/ueditor/ueditor.config.js"></script>
            <!-- 编辑器源码文件 -->
            <script type="text/javascript" src="/assets/js/ueditor/ueditor.all.js"></script>
            <!-- 语言包文件(建议手动加载语言包，避免在ie下，因为加载语言失败导致编辑器加载失败) -->
            <script type="text/javascript" src="/assets/js/ueditor/lang/zh-cn/zh-cn.js"></script>
            <script src="/assets/js/ajaxfileupload.js"></script>
            <script src="/assets/js/video.js"></script>

            <!-- date -->
            <script src="/assets/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
            <script src="/assets/js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
            <script type="text/javascript">
                $(function () {
                    $(".ui_timepicker").datetimepicker({
                        format: 'yyyy-mm-dd hh:ii:ss',
                        language:'zh-CN',
                        todayBtn:  1,
                        autoclose: 1,
                        todayHighlight: 1,
                        startView: 2,
                        forceParse: 0,
                    })
                })
            </script>
            <!-- date -->

            <div class="app_content_div" id="app_content_div_301Index">
                <h3>编辑视频</h3>
            </div>

            <form class="form-horizontal"  method="post" action="/adm/video/edi/{{$video->id}}">
                <input type="hidden" name="_token" id="_token" value="ymg4n0AUxWJluIOBnbhkXIMQiVH15m4jsb0SFtNr" />
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="title" name="title" value="title">
                    </div>
                </div>
                <div class="form-group">
                    <label for="url" class="col-sm-2 control-label"><span style="color:red;">*</span>视频路径</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="url" name="url" value="C:\Users\10116\Desktop\【4K】《偶像练习生》100 初印象 蔡徐坤自我介绍.mp4">
                    </div>
                </div>

                <div class="form-group">
                    <label for="type" class="col-sm-2 control-label"><span style="color:red;">*</span>视频类型</label>
                    <div class="col-sm-10">
                        <label class="radio-inline">
                            <input type="radio" name="type" id="video_type1" value="1" @if($video->type==1) checked @endif> 直播
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="type" id="video_type2" value="0" @if($video->type==0) checked @endif> 录播
                        </label>
                    </div>
                </div>
                <div class="form-group" >
                    <label for="description" class="col-sm-2 control-label"><span style="color:red;">*</span>课程简介</label>
                    <div class="col-sm-10">
                        <script id="description" name="description" type="text/plain"><p>12312312</p></script>
                        <script type="text/javascript">
                            var ue1 = UE.getEditor('jianli',{
                                elementPathEnabled: false,
                                saveInterval: 5000
                            });
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <label for="doc_department" class="col-sm-2 control-label"><span style="color:red;">*</span>直播开始时间</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control ui_timepicker" id="start_time" name="start_time" value="2023-05-26 21:55:58">
                    </div>
                </div>
                <div class="form-group">
                    <label for="doc_hospital" class="col-sm-2 control-label"><span style="color:red;">*</span>直播结束时间</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control ui_timepicker" id="end_time" name="end_time" value="2023-05-27 21:55:58" >
                    </div>
                </div>
                <div class="form-group">
                    <label for="upload_file" class="col-sm-2 control-label"><span style="color:red;">*</span>缩略图</label>
                    <div class="col-sm-10">
                        <input  id="upload_file" name="upload_file"  type="file" onchange="saveThumb()"/>
                        <input type="hidden" class="form-control" id="img_thumb" name="img_thumb" value="/upload/video_thumb/jpg/20230526/202305262158224739_s.jpg" >
                        <img style="width:320px;height:200px;" alt="" id="thumb" src="/upload/video_thumb/jpg/20230526/202305262158224739_s.jpg"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="expertlist" class="col-sm-2 control-label"><span style="color:red;">*</span>关联专家</label>
                    <div class="col-sm-10">
                        <select id="expert">
                            <option value="">请选择</option>
                            @foreach($oExpert as $v)
                                <option value="{{$v->id}}">{{$v->name}}</option>
                            @endforeach
                        </select>
                        <button class="btn btn-default" type="button" onclick="addexpert()">添加</button>
                        <style>
                            .expert{margin:5px;}
                        </style>
                        <div id="expertlist" name="expertlist">
                            <div>
                                <input type="hidden" value="3" name="doc_id[]">
                                <span class="expert">{{$v->name}}</span>
                                <span class="glyphicon glyphicon-remove mouse" onclick="$(this).parent().remove()"></span>
                            </div>

                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" onclick="update()" class="btn btn-default">确定</button>
                    </div>
                </div>
            </form>
            <script>
                function addexpert(){
                    var expert = $('#expert option:selected');
                    var flag = true;
                    var experthtml = '';
                    if(expert.val()){
                        $('#expertlist').find('input').each(function(){
                            if($(this).val()==expert.val()){
                                flag = false;
                                return false;
                            }
                        });
                        if(flag){
                            experthtml += '<div>';
                            experthtml += '		<input type="hidden" value="'+expert.val()+'" name="doc_id[]">';
                            experthtml += '		<span class="expert">'+expert.text()+'</span>';
                            experthtml += '		<span class="glyphicon glyphicon-remove mouse" onclick="$(this).parent().remove()"></span>';
                            experthtml += '</div>';
                            $('#expertlist').append(experthtml);
                        }else{
                            alert('您已经添加过该专家了');
                            return false;
                        }
                    }else{
                        alert('请先选择一个专家');
                        return false;
                    }
                }
            </script>
        </div>
    </div>
    <script>
        //这里是插件忽略
        $('#start_at').datetimepicker({
            format: 'Y-m-d H:i:s',
        });
        $('#end_at').datetimepicker({
            format: 'Y-m-d H:i:s',
        });
        $.datetimepicker.setLocale('zh');
        var ue = UE.getEditor('info', {
            elementPathEnabled: false,
            saveInterval: 5000
        });
        ue.ready(function () {
            $("#replyContent").html(ue.getContent());
        });
        function update(){
            var title = $('#title').val();
            var url = $('#url').val();
            var leixing=$("[name='type']:checked").eq(0).val();
            let introduce=ue1.getContentTxt();
            var kaishishijian = $('#start_time').val();
            var jieshushijian = $('#end_time').val();
            var _token = "{{csrf_token()}}";
            $.ajaxFileUpload({
                url:'/adm/video/edit/{{$video->id}}',
                type:'post',
                fileElementId:'thumb',
                dataType:'json',
                data:{'title':title,'url':url,'leixing':leixing,'introduce':introduce,'kaishishijian':kaishishijian,'jieshushijian':jieshushijian,
                    '_token': _token},
                success:function (data){
                    if(data.success){
                        alert(data.msg);
                        location.href='/video';
                    }else{
                        alert(data.msg);
                    }
                }
            });
        }
    </script>
@endsection
